package com.example.smart_city_0829.activity.waste_sorting;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

import com.example.smart_city_0829.R;
import com.example.smart_city_0829.base.BaseActivity;
import com.example.smart_city_0829.entity.waste_sorting.PostIm;
import com.example.smart_city_0829.entity.waste_sorting.Sort;
import com.example.smart_city_0829.retrofit.NetCallBack;
import com.example.smart_city_0829.view.MaxSizeGv;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

import retrofit2.Call;
import retrofit2.Response;

public class TypeActivity extends BaseActivity implements View.OnClickListener{

    private Banner banner;
    private Button b1;
    private Button b2;
    private Button b3;
    private Button b4;
    private LinearLayout linearLayout2;
    private MaxSizeGv gv;

    private Sort sort;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_type;
    }

    @Override
    protected void initView() {
        banner = (Banner) findViewById(R.id.banner);
        b1 = (Button) findViewById(R.id.b1);
        b2 = (Button) findViewById(R.id.b2);
        b3 = (Button) findViewById(R.id.b3);
        b4 = (Button) findViewById(R.id.b4);
        linearLayout2 = (LinearLayout) findViewById(R.id.linearLayout2);
        gv = (MaxSizeGv) findViewById(R.id.gv);
    }

    @Override
    protected void initData() {
        api.getGarbagePoster().enqueue(new NetCallBack<PostIm>() {
            @Override
            public void onResponse(@NonNull Call<PostIm> call, @NonNull Response<PostIm> response) {
                if (response.body() == null) return;

                final List<PostIm.DataBean> data = response.body().getData();
                banner.setImages(data.stream()
                        .map(PostIm.DataBean::getImgUrl)
                        .collect(Collectors.toList()));
                banner.setBannerTitles(data.stream()
                        .map(PostIm.DataBean::getTitle)
                        .collect(Collectors.toList()));
                banner.start();
                banner.startAutoPlay();
            }
        });

        api.getGarbageSort(null).enqueue(new NetCallBack<Sort>() {
            @Override
            public void onResponse(Call<Sort> call, Response<Sort> response) {
                if (response.body() == null) return;

                sort = response.body();
            }
        });
    }

    @Override
    protected void initEvent() {
        banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR_TITLE_INSIDE);
        banner.setImageLoader(imageLoader);

        b1.setOnClickListener(v -> {
            final Intent intent = new Intent(context, TypeIntroduceActivity.class);
            intent.putExtra("data", (Serializable) sort.getRows().stream()
                    .filter(rowsBean -> rowsBean.getId() == 8)
                    .collect(Collectors.toList()));
            startActivity(intent);
        });

        b2.setOnClickListener(v -> {
            final Intent intent = new Intent(context, TypeIntroduceActivity.class);
            intent.putExtra("data", (Serializable) sort.getRows().stream()
                    .filter(rowsBean -> rowsBean.getId() == 9)
                    .collect(Collectors.toList()));
            startActivity(intent);
        });

        b3.setOnClickListener(v -> {
            final Intent intent = new Intent(context, TypeIntroduceActivity.class);
            intent.putExtra("data", (Serializable) sort.getRows().stream()
                    .filter(rowsBean -> rowsBean.getId() == 10)
                    .collect(Collectors.toList()));
            startActivity(intent);
        });

        b4.setOnClickListener(v -> {
            final Intent intent = new Intent(context, TypeIntroduceActivity.class);
            intent.putExtra("data", (Serializable) sort.getRows().stream()
                    .filter(rowsBean -> rowsBean.getId() == 11)
                    .collect(Collectors.toList()));
            startActivity(intent);
        });
    }

    @Override
    protected String getActionBarTitle() {
        return "分类";
    }

    @Override
    public void onClick(View v) {

    }
}